from django.contrib import admin

# Register your models here.
from QA_tmp import settings
from product.models import ProductModel, ImagesModel, AnswerModel, ProblemModel


class AnswerInline(admin.TabularInline):
    model = AnswerModel


class ImagesInline(admin.TabularInline):
    model = ImagesModel


class ProblemInline(admin.TabularInline):
    model = ProblemModel


@admin.register(ProductModel)
class ProductAdmin(admin.ModelAdmin):
    list_display = ['title', 'first_image', 'type', 'create_time']
    inlines = [
        ImagesInline,
    ]
    # 分页
    list_per_page = settings.LIST_PER_PAGE
    # 排序方式
    ordering = ['create_time']
    # 允许搜索的字段
    search_fields = ['title']
    # 显示详细时间
    date_hierarchy = 'create_time'

    # 过滤器
    list_filter = ['type', 'create_time']


@admin.register(ProblemModel)
class ProblemAdmin(admin.ModelAdmin):
    # fields = ['title', 'product']
    list_display = ['title', 'product', 'create_time']  # 列表展示的字段
    inlines = [
        AnswerInline,
    ]
    list_per_page = settings.LIST_PER_PAGE
    ordering = ['create_time']

    search_fields = ['title']
    # 过滤器
    list_filter = ['product', 'create_time']


admin.site.site_title = 'QA问答后台管理'
admin.site.site_header = 'QA问答后台管理'
